<?php
// +----------------------------------------------------------------------
// | ZZYY  [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2023 https://www.fastadmin.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: 乘风
// +----------------------------------------------------------------------

namespace app\admin\model\zzyy;

use think\Model;


class ZzyyUserBalance extends Model
{

    const TYPE_RECHARGE = 1;
    const TYPE_SYSTEM_REFUND = 2;
    const TYPE_CONSUME = -1;

    // 表名
    protected $name = 'zzyy_user_balance';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
    ];



    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '-1' => __('Type -1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function paytransaction()
    {
        return $this->hasOne('ZzyyTransaction', 'id', 'transaction_id')->setEagerlyType(1);
    }

    public function reserve()
    {
        return $this->hasOne('ZzyyReserve', 'balance_id', 'id')->setEagerlyType(1);
    }



}